#!/bin/bash
#
source ../source/common/functions.sh
#set Var
NAME=`basename $0`
dir=`pwd`
conf=DIRCONFIG.ini
bak_dir=`readIni conf.ini backup backupdir`
packagename=`basename ${dir%/backup}`
sys=`echo ${packagename}|cut -d "-" -f2`
#Ĭ��ѡȡ���һ�εı��ݽ��лָ�
restore_file=`ls -t /home/BackupGED.bak/|grep ${sys}|sed -n '1p'`

function Restore() {
	local file=$1
	local directory=$2
	tar xvf ${file} -C ${directory}
}

function RestoreStep() {
	IFS=$'\n'
	for xpath in `cat ${conf}|grep -v ^#`
	do
		if [ X"$xpath" = X ]
		then
			yaoecho hr "DIRCONFIG file have no content ! Please check it ! [${NAME}]"
			EchoErr ${LINENO}
			exit 1
		fi
		local restorefile=`echo ${xpath}|awk -F"=" '{print $1}'`
		local restoredir=`cat ${conf}|awk -F"=" '{print $2}'|awk -F";" '{print $1}'`
		if ( [ X"${restorefile}" = X ] || [ X"${restoredir}" = X ] )
		then
			yaoecho hr "DIRCONFIG file  error ! Please check it !"
			EchoErr ${LINENO}
			exit 1
		fi
		yaoecho hg "start restore..."
		cd ${bak_dir}
		tar xvf ${restore_file} --strip-components 1
		Restore ${restorefile}.tgz ${restoredir}
	done
}

#
yaoecho hv "Start restore..."
#service ${} stop
RestoreStep
#service ${}	restart
yaoecho hg "Restore finish"

